// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.SQLUtils;
// import com.alibaba.druid.sql.ast.SQLDataType;
// import com.alibaba.druid.sql.ast.SQLDataTypeImpl;
// import com.alibaba.druid.sql.ast.SQLExprImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.Collections;
// import java.util.List;

#include "SQLJSONExpr.h"
#include "../SQLDataTypeImpl.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../SQLUtils.h"

SQLDataType_ptr SQLJSONExpr::DATA_TYPE = SQLDataType_ptr(new SQLDataTypeImpl(make_string_ptr("JSON")));

SQLJSONExpr::SQLJSONExpr()
{
}

SQLJSONExpr::SQLJSONExpr(string_ptr literal)
{
  this->literal = literal;
}

SQLObject_ptr SQLJSONExpr::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLJSONExpr>(new SQLJSONExpr(literal));
  std::shared_ptr<SQLJSONExpr> x = std::dynamic_pointer_cast<SQLJSONExpr>(clone_tmp);
  // SQLJSONExpr x = new SQLJSONExpr(literal);
  return x;
}

string_ptr SQLJSONExpr::getValue()
{
  return literal;
}

string_ptr SQLJSONExpr::getLiteral()
{
  return literal;
}

void SQLJSONExpr::setLiteral(string_ptr literal)
{
  this->literal = literal;
}

//@Override
bool SQLJSONExpr::equals(Object_ptr o)
{
  if (this == o.get())
  {
    return true;
  }
  if (o == nullptr || getClass() != o->getClass())
  {
    return false;
  }

  std::shared_ptr<SQLJSONExpr> that = std::dynamic_pointer_cast<SQLJSONExpr>(o);

  return !literal->empty() ? (literal == that->literal) : that->literal->empty();
}

//@Override
int SQLJSONExpr::hashCode()
{
  return !literal->empty() ? literal->size() : 0;
}

//@Override
void SQLJSONExpr::accept0(SQLASTVisitor_ptr visitor)
{
  visitor->visit(SharedObject(SQLJSONExpr));

  visitor->endVisit(SharedObject(SQLJSONExpr));
}

string_ptr SQLJSONExpr::toString()
{
  return (SQLUtils::toSQLString(std::dynamic_pointer_cast< SQLObject>(SharedObject(SQLJSONExpr)), (DbType_ptr) nullptr));
}

SQLDataType_ptr SQLJSONExpr::computeDataType()
{
  return DATA_TYPE;
}

//@Override
SQLObject_list_ptr SQLJSONExpr::getChildren()
{
  return SQLObject_list_ptr();
}
